//-------------------------------------------------------
/*
 * VegaGUI.java
 *
 * Created on March 17, 2008, 5:52 PM
 */
package graphalgorithmgui;

import vega.Test;
import vega.graph.AbstractGraph;
import interfaces.algorithms.GraphAlgorithm;
import vega.algorithms.Dijkstra;
import vega.algorithms.GraphAlgorithms;
import vega.algorithms.tsp.NearestNeighbor;
import vega.algorithms.tsp.TwoOpt;
import interfaces.graph.Graph;
import interfaces.graph.edge.Edge;
import interfaces.graph.vertex.Vertex;
import interfaces.graph.edge.UndirectedEdge;

import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;

/**
 * 
 * @author w_jossey
 */
public class VegaGUI extends javax.swing.JFrame {

	GraphAlgorithm a = null;

	/** Creates new form VegaGUI */
	public VegaGUI() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		inputContainerPanel = new javax.swing.JPanel();
		propertiesLabel = new javax.swing.JLabel();
		verticesLabel = new javax.swing.JLabel();
		vertexTextField = new javax.swing.JTextField();
		edgesLabel = new javax.swing.JLabel();
		edgeTextField = new javax.swing.JTextField();
		completeGraphCheckBox = new javax.swing.JCheckBox();
		generateGraphButton = new javax.swing.JButton();
		specialGraphsComboBox = new javax.swing.JComboBox();
		algorithmComboBox = new javax.swing.JComboBox();
		controlContainerPanel = new javax.swing.JPanel();
		controlsLabel = new javax.swing.JLabel();
		forwardButton = new javax.swing.JButton();
		speedLabel = new javax.swing.JLabel();
		playButton = new javax.swing.JButton();
		backButton = new javax.swing.JButton();
		speedSlider = new javax.swing.JSlider();
		alertLabel = new javax.swing.JLabel();
		pseudoCodeContainerPanel = new javax.swing.JPanel();
		pseudoCodeLabel = new javax.swing.JLabel();
		pseudoCodeScrollPane = new javax.swing.JScrollPane();
		pseudoCodeTextArea = new javax.swing.JTextArea();
		imageContainerPanel = new javax.swing.JPanel();
		graphViewerLabel = new javax.swing.JLabel();
		imagePanel = new graphalgorithmgui.ImagePanel();
		menuBar = new javax.swing.JMenuBar();
		fileMenu = new javax.swing.JMenu();
		openMenuItem = new javax.swing.JMenuItem();
		jMenuItem1 = new javax.swing.JMenuItem();
		saveMenuItem = new javax.swing.JMenuItem();
		saveAsMenuItem = new javax.swing.JMenuItem();
		exitMenuItem = new javax.swing.JMenuItem();
		jMenu1 = new javax.swing.JMenu();
		jMenuItem2 = new javax.swing.JMenuItem();
		editMenu = new javax.swing.JMenu();
		cutMenuItem = new javax.swing.JMenuItem();
		copyMenuItem = new javax.swing.JMenuItem();
		pasteMenuItem = new javax.swing.JMenuItem();
		deleteMenuItem = new javax.swing.JMenuItem();
		helpMenu = new javax.swing.JMenu();
		contentsMenuItem = new javax.swing.JMenuItem();
		aboutMenuItem = new javax.swing.JMenuItem();
		menuBar1 = new javax.swing.JMenuBar();
		fileMenu1 = new javax.swing.JMenu();
		openMenuItem1 = new javax.swing.JMenuItem();
		jMenuItem3 = new javax.swing.JMenuItem();
		saveMenuItem1 = new javax.swing.JMenuItem();
		saveAsMenuItem1 = new javax.swing.JMenuItem();
		exitMenuItem1 = new javax.swing.JMenuItem();
		jMenu2 = new javax.swing.JMenu();
		jMenuItem4 = new javax.swing.JMenuItem();
		editMenu1 = new javax.swing.JMenu();
		cutMenuItem1 = new javax.swing.JMenuItem();
		copyMenuItem1 = new javax.swing.JMenuItem();
		pasteMenuItem1 = new javax.swing.JMenuItem();
		deleteMenuItem1 = new javax.swing.JMenuItem();
		helpMenu1 = new javax.swing.JMenu();
		contentsMenuItem1 = new javax.swing.JMenuItem();
		aboutMenuItem1 = new javax.swing.JMenuItem();
		menuBar2 = new javax.swing.JMenuBar();
		fileMenu2 = new javax.swing.JMenu();
		openMenuItem2 = new javax.swing.JMenuItem();
		jMenuItem5 = new javax.swing.JMenuItem();
		saveMenuItem2 = new javax.swing.JMenuItem();
		saveAsMenuItem2 = new javax.swing.JMenuItem();
		exitMenuItem2 = new javax.swing.JMenuItem();
		jMenu3 = new javax.swing.JMenu();
		jMenuItem6 = new javax.swing.JMenuItem();
		editMenu2 = new javax.swing.JMenu();
		cutMenuItem2 = new javax.swing.JMenuItem();
		copyMenuItem2 = new javax.swing.JMenuItem();
		pasteMenuItem2 = new javax.swing.JMenuItem();
		deleteMenuItem2 = new javax.swing.JMenuItem();
		helpMenu2 = new javax.swing.JMenu();
		contentsMenuItem2 = new javax.swing.JMenuItem();
		aboutMenuItem2 = new javax.swing.JMenuItem();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("V.E.G.A.");
		setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
		setName("MainFrame"); // NOI18N
		setResizable(false);

		inputContainerPanel.setBorder(javax.swing.BorderFactory
				.createEtchedBorder(java.awt.Color.white,
						java.awt.Color.lightGray));

		propertiesLabel.setText("Properties");

		verticesLabel.setText("Vertices:");

		vertexTextField.setColumns(8);

		edgesLabel.setText("Edges:");

		edgeTextField.setColumns(8);

		completeGraphCheckBox.setText("Complete");
		completeGraphCheckBox
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						completeGraphCheckBoxActionPerformed(evt);
					}
				});

		generateGraphButton.setText("Generate");
		generateGraphButton
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						generateGraphButtonActionPerformed(evt);
					}
				});

		specialGraphsComboBox.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Special Graphs", "Complete Graphs", "Trees",
						"Networks", "Directed Graphs" }));
		specialGraphsComboBox
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						specialGraphsComboBoxActionPerformed(evt);
					}
				});

		algorithmComboBox.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "2-OPT", "Nearest Neighbor", "Dijkstra", "Fibonnaci Heaps", "Binary Heaps", "Binomail Heap", "Heap", "Binary Search Tree", "Red Black Tree", "Kruskal's", "Prim's" }));

		org.jdesktop.layout.GroupLayout inputContainerPanelLayout = new org.jdesktop.layout.GroupLayout(
				inputContainerPanel);
		inputContainerPanel.setLayout(inputContainerPanelLayout);
		inputContainerPanelLayout
				.setHorizontalGroup(inputContainerPanelLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								inputContainerPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												inputContainerPanelLayout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																completeGraphCheckBox)
														.add(propertiesLabel)
														.add(
																inputContainerPanelLayout
																		.createParallelGroup(
																				org.jdesktop.layout.GroupLayout.TRAILING,
																				false)
																		.add(
																				org.jdesktop.layout.GroupLayout.LEADING,
																				specialGraphsComboBox,
																				0,
																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)
																		.add(
																				org.jdesktop.layout.GroupLayout.LEADING,
																				algorithmComboBox,
																				0,
																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)
																		.add(
																				org.jdesktop.layout.GroupLayout.LEADING,
																				inputContainerPanelLayout
																						.createSequentialGroup()
																						.add(
																								inputContainerPanelLayout
																										.createParallelGroup(
																												org.jdesktop.layout.GroupLayout.LEADING)
																										.add(
																												verticesLabel)
																										.add(
																												edgesLabel))
																						.add(
																								18,
																								18,
																								18)
																						.add(
																								inputContainerPanelLayout
																										.createParallelGroup(
																												org.jdesktop.layout.GroupLayout.LEADING)
																										.add(
																												edgeTextField,
																												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
																										.add(
																												vertexTextField,
																												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
																										.add(
																												org.jdesktop.layout.GroupLayout.TRAILING,
																												generateGraphButton)))))
										.addContainerGap()));
		inputContainerPanelLayout
				.setVerticalGroup(inputContainerPanelLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								inputContainerPanelLayout
										.createSequentialGroup()
										.add(propertiesLabel)
										.add(18, 18, 18)
										.add(
												specialGraphsComboBox,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(5, 5, 5)
										.add(
												algorithmComboBox,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.add(18, 18, 18)
										.add(
												inputContainerPanelLayout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(
																vertexTextField,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
														.add(verticesLabel))
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												inputContainerPanelLayout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(edgesLabel)
														.add(
																edgeTextField,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(completeGraphCheckBox)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(generateGraphButton)
										.addContainerGap(137, Short.MAX_VALUE)));

		controlContainerPanel.setBorder(javax.swing.BorderFactory
				.createEtchedBorder(java.awt.Color.white,
						java.awt.Color.lightGray));

		controlsLabel.setText("Controls");

		forwardButton.setAction(new LongRunningNextImageButtonAction());
		forwardButton.setText(">>");
		forwardButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				forwardButtonActionPerformed(evt);
			}
		});

		speedLabel.setText("Speed:");

		playButton.setText(">");
		playButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				playButtonActionPerformed(evt);
			}
		});

		backButton.setText("<<");
		backButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				backButtonActionPerformed(evt);
			}
		});

		speedSlider.setMajorTickSpacing(25);
		speedSlider.setMinorTickSpacing(25);

		alertLabel.setText("Status:");

		org.jdesktop.layout.GroupLayout controlContainerPanelLayout = new org.jdesktop.layout.GroupLayout(
				controlContainerPanel);
		controlContainerPanel.setLayout(controlContainerPanelLayout);
		controlContainerPanelLayout
				.setHorizontalGroup(controlContainerPanelLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								controlContainerPanelLayout
										.createSequentialGroup()
										.addContainerGap().add(controlsLabel)
										.addContainerGap(148, Short.MAX_VALUE))
						.add(
								org.jdesktop.layout.GroupLayout.TRAILING,
								controlContainerPanelLayout
										.createSequentialGroup()
										.addContainerGap(
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.add(
												backButton,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												67,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												playButton,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												50,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.UNRELATED)
										.add(
												forwardButton,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												67,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addContainerGap())
						.add(
								org.jdesktop.layout.GroupLayout.TRAILING,
								controlContainerPanelLayout
										.createSequentialGroup()
										.addContainerGap(22, Short.MAX_VALUE)
										.add(
												controlContainerPanelLayout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(alertLabel)
														.add(
																controlContainerPanelLayout
																		.createSequentialGroup()
																		.add(
																				speedLabel)
																		.addPreferredGap(
																				org.jdesktop.layout.LayoutStyle.RELATED)
																		.add(
																				speedSlider,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																				143,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
										.add(12, 12, 12)));
		controlContainerPanelLayout
				.setVerticalGroup(controlContainerPanelLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								controlContainerPanelLayout
										.createSequentialGroup()
										.add(controlsLabel)
										.add(8, 8, 8)
										.add(
												controlContainerPanelLayout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(playButton).add(
																forwardButton)
														.add(backButton))
										.add(18, 18, 18)
										.add(
												controlContainerPanelLayout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																controlContainerPanelLayout
																		.createSequentialGroup()
																		.add(
																				speedLabel)
																		.add(
																				39,
																				39,
																				39)
																		.add(
																				alertLabel))
														.add(
																speedSlider,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(36, Short.MAX_VALUE)));

		pseudoCodeContainerPanel.setBorder(javax.swing.BorderFactory
				.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED,
						java.awt.Color.white, java.awt.Color.lightGray));

		pseudoCodeLabel.setText("Pseudo-Code");

		pseudoCodeTextArea.setColumns(20);
		pseudoCodeTextArea.setEditable(false);
		pseudoCodeTextArea.setRows(6);
		pseudoCodeScrollPane.setViewportView(pseudoCodeTextArea);

		org.jdesktop.layout.GroupLayout pseudoCodeContainerPanelLayout = new org.jdesktop.layout.GroupLayout(
				pseudoCodeContainerPanel);
		pseudoCodeContainerPanel.setLayout(pseudoCodeContainerPanelLayout);
		pseudoCodeContainerPanelLayout
				.setHorizontalGroup(pseudoCodeContainerPanelLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								pseudoCodeContainerPanelLayout
										.createSequentialGroup()
										.add(
												pseudoCodeContainerPanelLayout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																pseudoCodeContainerPanelLayout
																		.createSequentialGroup()
																		.add(
																				175,
																				175,
																				175)
																		.add(
																				pseudoCodeLabel))
														.add(
																pseudoCodeContainerPanelLayout
																		.createSequentialGroup()
																		.addContainerGap()
																		.add(
																				pseudoCodeScrollPane,
																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																				783,
																				Short.MAX_VALUE)))
										.addContainerGap()));
		pseudoCodeContainerPanelLayout
				.setVerticalGroup(pseudoCodeContainerPanelLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								pseudoCodeContainerPanelLayout
										.createSequentialGroup()
										.add(pseudoCodeLabel)
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												pseudoCodeScrollPane,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
												118,
												org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
										.addContainerGap(36, Short.MAX_VALUE)));

		imageContainerPanel.setBorder(javax.swing.BorderFactory
				.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED,
						null, java.awt.Color.lightGray));

		graphViewerLabel.setText("Graph Viewer");

		org.jdesktop.layout.GroupLayout imagePanelLayout = new org.jdesktop.layout.GroupLayout(
				imagePanel);
		imagePanel.setLayout(imagePanelLayout);
		imagePanelLayout.setHorizontalGroup(imagePanelLayout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(0, 783, Short.MAX_VALUE));
		imagePanelLayout.setVerticalGroup(imagePanelLayout.createParallelGroup(
				org.jdesktop.layout.GroupLayout.LEADING).add(0, 325,
				Short.MAX_VALUE));

		org.jdesktop.layout.GroupLayout imageContainerPanelLayout = new org.jdesktop.layout.GroupLayout(
				imageContainerPanel);
		imageContainerPanel.setLayout(imageContainerPanelLayout);
		imageContainerPanelLayout
				.setHorizontalGroup(imageContainerPanelLayout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								imageContainerPanelLayout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												imageContainerPanelLayout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																imagePanel,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.add(graphViewerLabel))
										.addContainerGap()));
		imageContainerPanelLayout.setVerticalGroup(imageContainerPanelLayout
				.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
				.add(
						imageContainerPanelLayout.createSequentialGroup().add(
								graphViewerLabel).add(10, 10, 10).add(
								imagePanel,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE).addContainerGap()));

		fileMenu.setText("File");

		openMenuItem.setText("Open Graph");
		fileMenu.add(openMenuItem);

		jMenuItem1.setText("Import Algorithm");
		fileMenu.add(jMenuItem1);

		saveMenuItem.setText("Save Graph");
		fileMenu.add(saveMenuItem);

		saveAsMenuItem.setText("Save Graph As ...");
		fileMenu.add(saveAsMenuItem);

		exitMenuItem.setText("Exit");
		exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				exitMenuItemActionPerformed(evt);
			}
		});
		fileMenu.add(exitMenuItem);

		menuBar.add(fileMenu);

		jMenu1.setText("Algorithm");

		jMenuItem2.setText("Select Algorithm");
		jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jMenuItem2MouseClicked(evt);
			}
		});
		jMenu1.add(jMenuItem2);

		menuBar.add(jMenu1);

		editMenu.setText("Edit");

		cutMenuItem.setText("Cut");
		editMenu.add(cutMenuItem);

		copyMenuItem.setText("Copy");
		editMenu.add(copyMenuItem);

		pasteMenuItem.setText("Paste");
		editMenu.add(pasteMenuItem);

		deleteMenuItem.setText("Delete");
		editMenu.add(deleteMenuItem);

		menuBar.add(editMenu);

		helpMenu.setText("Help");

		contentsMenuItem.setText("Contents");
		helpMenu.add(contentsMenuItem);

		aboutMenuItem.setText("About");
		helpMenu.add(aboutMenuItem);

		menuBar.add(helpMenu);

		fileMenu1.setText("File");

		openMenuItem1.setText("Open Graph");
		fileMenu1.add(openMenuItem1);

		jMenuItem3.setText("Import Algorithm");
		fileMenu1.add(jMenuItem3);

		saveMenuItem1.setText("Save Graph");
		fileMenu1.add(saveMenuItem1);

		saveAsMenuItem1.setText("Save Graph As ...");
		fileMenu1.add(saveAsMenuItem1);

		exitMenuItem1.setText("Exit");
		exitMenuItem1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				exitMenuItemActionPerformed(evt);
			}
		});
		fileMenu1.add(exitMenuItem1);

		menuBar1.add(fileMenu1);

		jMenu2.setText("Algorithm");

		jMenuItem4.setText("Select Algorithm");
		jMenuItem4.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jMenuItem2MouseClicked(evt);
			}
		});
		jMenu2.add(jMenuItem4);

		menuBar1.add(jMenu2);

		editMenu1.setText("Edit");

		cutMenuItem1.setText("Cut");
		editMenu1.add(cutMenuItem1);

		copyMenuItem1.setText("Copy");
		editMenu1.add(copyMenuItem1);

		pasteMenuItem1.setText("Paste");
		editMenu1.add(pasteMenuItem1);

		deleteMenuItem1.setText("Delete");
		editMenu1.add(deleteMenuItem1);

		menuBar1.add(editMenu1);

		helpMenu1.setText("Help");

		contentsMenuItem1.setText("Contents");
		helpMenu1.add(contentsMenuItem1);

		aboutMenuItem1.setText("About");
		helpMenu1.add(aboutMenuItem1);

		menuBar1.add(helpMenu1);

		fileMenu2.setText("File");

		openMenuItem2.setText("Open Graph");
		fileMenu2.add(openMenuItem2);

		jMenuItem5.setText("Import Algorithm");
		fileMenu2.add(jMenuItem5);

		saveMenuItem2.setText("Save Graph");
		fileMenu2.add(saveMenuItem2);

		saveAsMenuItem2.setText("Save Graph As ...");
		fileMenu2.add(saveAsMenuItem2);

		exitMenuItem2.setText("Exit");
		exitMenuItem2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				exitMenuItemActionPerformed(evt);
			}
		});
		fileMenu2.add(exitMenuItem2);

		menuBar2.add(fileMenu2);

		jMenu3.setText("Algorithm");

		jMenuItem6.setText("Select Algorithm");
		jMenuItem6.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jMenuItem2MouseClicked(evt);
			}
		});
		jMenu3.add(jMenuItem6);

		menuBar2.add(jMenu3);

		editMenu2.setText("Edit");

		cutMenuItem2.setText("Cut");
		editMenu2.add(cutMenuItem2);

		copyMenuItem2.setText("Copy");
		editMenu2.add(copyMenuItem2);

		pasteMenuItem2.setText("Paste");
		editMenu2.add(pasteMenuItem2);

		deleteMenuItem2.setText("Delete");
		editMenu2.add(deleteMenuItem2);

		menuBar2.add(editMenu2);

		helpMenu2.setText("Help");

		contentsMenuItem2.setText("Contents");
		helpMenu2.add(contentsMenuItem2);

		aboutMenuItem2.setText("About");
		helpMenu2.add(aboutMenuItem2);

		menuBar2.add(helpMenu2);

		setJMenuBar(menuBar2);

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								layout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																controlContainerPanel,
																0, 226,
																Short.MAX_VALUE)
														.add(
																inputContainerPanel,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.UNRELATED)
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING,
																false)
														.add(
																imageContainerPanel,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.add(
																pseudoCodeContainerPanel,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE))
										.addContainerGap(
												org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								org.jdesktop.layout.GroupLayout.TRAILING,
								layout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																imageContainerPanel,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.add(
																inputContainerPanel,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE))
										.addPreferredGap(
												org.jdesktop.layout.LayoutStyle.RELATED)
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																pseudoCodeContainerPanel,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																Short.MAX_VALUE)
														.add(
																controlContainerPanel,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.addContainerGap()));

		pack();
	}// </editor-fold>

	private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {// GEN
																				// -
																				// FIRST
																				// :
																				// event_exitMenuItemActionPerformed
		System.exit(0);
	}// GEN-LAST:event_exitMenuItemActionPerformed

	private class LongRunningNextImageButtonAction extends AbstractAction {

		/**
		 * 
		 */
		private static final long serialVersionUID = -3349336468849400316L;

		public LongRunningNextImageButtonAction() {
			super();
		}

		public void actionPerformed(ActionEvent arg0) {
			VegaGUI.this.alertLabel.setVisible(true);
			LoadNextImageRunnable loadNextImageRunnable = new LoadNextImageRunnable();
			Thread loadNextImageThread = new Thread(loadNextImageRunnable);
			loadNextImageThread.start();

		}
	}

	private class LoadNextImageRunnable implements Runnable {

		public void run() {
			if (a != null) {
				try {
					while (a.isRunning()) {
						if (VegaGUI.this.alertLabel.getText().equalsIgnoreCase(
								"Status:  Loading Image")) {
							VegaGUI.this.alertLabel
									.setText("Status:  Loading Image .");
						} else {
							if (VegaGUI.this.alertLabel.getText()
									.equalsIgnoreCase(
											"Status:  Loading Image .")) {
								VegaGUI.this.alertLabel
										.setText("Status:  Loading Image ..");
							} else {
								if (VegaGUI.this.alertLabel.getText()
										.equalsIgnoreCase(
												"Status:  Loading Image ..")) {
									VegaGUI.this.alertLabel
											.setText("Status:  Loading Image ...");
								} else {
									if (VegaGUI.this.alertLabel
											.getText()
											.equalsIgnoreCase(
													"Status:  Loading Image ...")) {
										VegaGUI.this.alertLabel
												.setText("Status:  Loading Image");
									} else {
										alertLabel
												.setText("Status:  Loading Image");
									}
								}
							}
						}
						Thread.sleep(1000);
					}
				} catch (InterruptedException ex) {
					Logger.getLogger(VegaGUI.class.getName()).log(Level.SEVERE,
							null, ex);
				}
				String[] returnTuple;
				returnTuple = a.getController().getNextGraphImage();
				if (returnTuple != null) {
					String fileName = returnTuple[0];
					String pseudoCodeText = returnTuple[1];

					try {
						if (fileName != null) {
							imagePanel.loadImage(fileName);
							imagePanel.scaleImage();
							pseudoCodeTextArea.setText(pseudoCodeText);
							repaint();

							VegaGUI.this.alertLabel.setVisible(false);
						}
					} catch (IOException ex) {
						Logger.getLogger(VegaGUI.class.getName()).log(
								Level.SEVERE, null, ex);
					}
				} else {
					alertLabel.setText("");
				}
			}
		}
	}

	private void forwardButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN
																				// -
																				// FIRST
																				// :
																				// event_forwardButtonActionPerformed

		// TODO add your handling code here:
	}// GEN-LAST:event_forwardButtonActionPerformed

	private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN
																			// -
																			// FIRST
																			// :
																			// event_playButtonActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_playButtonActionPerformed

	private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN
																			// -
																			// FIRST
																			// :
																			// event_backButtonActionPerformed
		try {
			if (a != null) {
				String[] returnTuple;
				returnTuple = a.getController().getPreviousGraphImage();
				if (returnTuple != null) {
					String fileName = returnTuple[0];
					String pseudoCodeText = returnTuple[1];

					if (fileName != null) {
						alertLabel.setVisible(false);
						imagePanel.loadImage(fileName);
						imagePanel.scaleImage();
						pseudoCodeTextArea.setText(pseudoCodeText);
						repaint();
					}
				} else {
					alertLabel.setText("");
				}

			} else {
				// Alert label to tell the User that they need to run an
				// algorithm first
				alertLabel.setText("");
			}

		} catch (IOException ex) {
			Logger.getLogger(VegaGUI.class.getName()).log(Level.SEVERE, null,
					ex);
		}
	}// GEN-LAST:event_backButtonActionPerformed

	private void completeGraphCheckBoxActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:
												// event_completeGraphCheckBoxActionPerformed
		// TODO add your handling code here:
		if (completeGraphCheckBox.isSelected()) {
			edgeTextField.setEditable(false);
			String vertexString = vertexTextField.getText();
			if (!vertexString.equalsIgnoreCase("")) {
				int vertexNum = Integer.parseInt(vertexString);
				int edgeNum = ((vertexNum * (vertexNum - 1)) / 2);
				edgeTextField.setText("" + edgeNum);
			}

		} else {
			edgeTextField.setEditable(true);
		}

	}// GEN-LAST:event_completeGraphCheckBoxActionPerformed

	private void specialGraphsComboBoxActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:
												// event_specialGraphsComboBoxActionPerformed
		// TODO add your handling code here:
		int selectedIndex = specialGraphsComboBox.getSelectedIndex();

		switch (selectedIndex) {
		case 0:
			break;
		case 1:
			// complete
			break;
		case 2:
			// tree
			break;
		case 3:
			// network
			break;
		case 4:
			// Directed
			break;
		default:
			break;

		}
	}// GEN-LAST:event_specialGraphsComboBoxActionPerformed

	private void jMenuItem2MouseClicked(java.awt.event.MouseEvent evt) {// GEN-
																		// FIRST
																		// :
																		// event_jMenuItem2MouseClicked
		// TODO add your handling code here:

		/* Open algorithm selection window... Freeze background */
	}// GEN-LAST:event_jMenuItem2MouseClicked

	private void generateGraphButtonActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:
												// event_generateGraphButtonActionPerformed
		// TODO add your handling code here:
		if (completeGraphCheckBox.isSelected()) {

			String algorithmString = algorithmComboBox.getSelectedItem()
					.toString();

			String vertexNumber = vertexTextField.getText();
			if (!vertexNumber.equalsIgnoreCase("")) {
				try {
					AbstractGraph<? extends Vertex<? extends Edge>, ? extends Edge> g = null;
					int vertexInt = Integer.parseInt(vertexNumber);
					int edgeNum = ((vertexInt * (vertexInt - 1)) / 2);
					edgeTextField.setText("" + edgeNum);
					if (vertexInt > 1) {

						if (algorithmString.equalsIgnoreCase("2-OPT")) {
							g = new AbstractGraph<Vertex<UndirectedEdge>, UndirectedEdge>(vertexInt, edgeNum, false);
							g.generateRandomGraph(true);
							a = new TwoOpt<Vertex<UndirectedEdge>, UndirectedEdge>();

						} else {
							if (algorithmString
									.equalsIgnoreCase("Nearest Neighbor")) {
								g = new AbstractGraph(vertexInt, false);
								a = new NearestNeighbor();
							} else {
								if (algorithmString
										.equalsIgnoreCase("Dijkstra")) {
									g = Test.demoGraph();
									a = new Dijkstra();
								}
							}
						}
						Runnable runnableGraphAlgorithm = new GraphAlgorithms(
								a, g);
						Thread thread = new Thread(runnableGraphAlgorithm);
						thread.start();

						try {
							while (a.getController() == null) {
								synchronized (this) {
									wait(1000);
								}
							}
							pseudoCodeTextArea.setText(a.getController()
									.getPseudoCodeWithoutLineMarker());
						} catch (InterruptedException ex) {
							Logger.getLogger(VegaGUI.class.getName()).log(
									Level.SEVERE, null, ex);
						}
					} else {
						/* The vertex value is less than or equal to 1 */
						alertLabel
								.setText("Please enter an integer great than 1");
					}
				} catch (java.lang.NumberFormatException e) {
					System.err
							.println("Error caught and handled: e.getMessage()");
				}

			} else {
				/* We have something invalid in the vertex box. */
				alertLabel.setText("Invalid value");
			}
		} else {
			/* The complete graph checkbox is not checked */
			System.err.println("Not yet implemented");

			/*
			 * String vertexNumber = vertexTextField.getText(); int vertexInt =
			 * Integer.parseInt(vertexNumber); String edgeNumber =
			 * edgeTextField.getText(); int edgeInt =
			 * Integer.parseInt(edgeNumber); Graph g = new Graph(vertexInt,
			 * edgeInt, false); twoOptInstance = new TwoOpt(); Runnable
			 * runnableGraphAlgorithm = new GraphAlgorithms(twoOptInstance, g);
			 * Thread thread = new Thread(runnableGraphAlgorithm);
			 * thread.start();
			 */
		}

	}// GEN-LAST:event_generateGraphButtonActionPerformed

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				new VegaGUI().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify
	private javax.swing.JMenuItem aboutMenuItem;
	private javax.swing.JMenuItem aboutMenuItem1;
	private javax.swing.JMenuItem aboutMenuItem2;
	private javax.swing.JLabel alertLabel;
	private javax.swing.JComboBox algorithmComboBox;
	private javax.swing.JButton backButton;
	private javax.swing.JCheckBox completeGraphCheckBox;
	private javax.swing.JMenuItem contentsMenuItem;
	private javax.swing.JMenuItem contentsMenuItem1;
	private javax.swing.JMenuItem contentsMenuItem2;
	private javax.swing.JPanel controlContainerPanel;
	private javax.swing.JLabel controlsLabel;
	private javax.swing.JMenuItem copyMenuItem;
	private javax.swing.JMenuItem copyMenuItem1;
	private javax.swing.JMenuItem copyMenuItem2;
	private javax.swing.JMenuItem cutMenuItem;
	private javax.swing.JMenuItem cutMenuItem1;
	private javax.swing.JMenuItem cutMenuItem2;
	private javax.swing.JMenuItem deleteMenuItem;
	private javax.swing.JMenuItem deleteMenuItem1;
	private javax.swing.JMenuItem deleteMenuItem2;
	private javax.swing.JTextField edgeTextField;
	private javax.swing.JLabel edgesLabel;
	private javax.swing.JMenu editMenu;
	private javax.swing.JMenu editMenu1;
	private javax.swing.JMenu editMenu2;
	private javax.swing.JMenuItem exitMenuItem;
	private javax.swing.JMenuItem exitMenuItem1;
	private javax.swing.JMenuItem exitMenuItem2;
	private javax.swing.JMenu fileMenu;
	private javax.swing.JMenu fileMenu1;
	private javax.swing.JMenu fileMenu2;
	private javax.swing.JButton forwardButton;
	private javax.swing.JButton generateGraphButton;
	private javax.swing.JLabel graphViewerLabel;
	private javax.swing.JMenu helpMenu;
	private javax.swing.JMenu helpMenu1;
	private javax.swing.JMenu helpMenu2;
	private javax.swing.JPanel imageContainerPanel;
	private graphalgorithmgui.ImagePanel imagePanel;
	private javax.swing.JPanel inputContainerPanel;
	private javax.swing.JMenu jMenu1;
	private javax.swing.JMenu jMenu2;
	private javax.swing.JMenu jMenu3;
	private javax.swing.JMenuItem jMenuItem1;
	private javax.swing.JMenuItem jMenuItem2;
	private javax.swing.JMenuItem jMenuItem3;
	private javax.swing.JMenuItem jMenuItem4;
	private javax.swing.JMenuItem jMenuItem5;
	private javax.swing.JMenuItem jMenuItem6;
	private javax.swing.JMenuBar menuBar;
	private javax.swing.JMenuBar menuBar1;
	private javax.swing.JMenuBar menuBar2;
	private javax.swing.JMenuItem openMenuItem;
	private javax.swing.JMenuItem openMenuItem1;
	private javax.swing.JMenuItem openMenuItem2;
	private javax.swing.JMenuItem pasteMenuItem;
	private javax.swing.JMenuItem pasteMenuItem1;
	private javax.swing.JMenuItem pasteMenuItem2;
	private javax.swing.JButton playButton;
	private javax.swing.JLabel propertiesLabel;
	private javax.swing.JPanel pseudoCodeContainerPanel;
	private javax.swing.JLabel pseudoCodeLabel;
	private javax.swing.JScrollPane pseudoCodeScrollPane;
	private javax.swing.JTextArea pseudoCodeTextArea;
	private javax.swing.JMenuItem saveAsMenuItem;
	private javax.swing.JMenuItem saveAsMenuItem1;
	private javax.swing.JMenuItem saveAsMenuItem2;
	private javax.swing.JMenuItem saveMenuItem;
	private javax.swing.JMenuItem saveMenuItem1;
	private javax.swing.JMenuItem saveMenuItem2;
	private javax.swing.JComboBox specialGraphsComboBox;
	private javax.swing.JLabel speedLabel;
	private javax.swing.JSlider speedSlider;
	private javax.swing.JTextField vertexTextField;
	private javax.swing.JLabel verticesLabel;
	// End of variables declaration
}
